package team.knowers.qzh.qzhserver.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.qzh.qzhserver.common.convention.result.Result;
import team.knowers.qzh.qzhserver.common.convention.result.Results;
import team.knowers.qzh.qzhserver.dao.entity.QuestionAnswerDO;
import team.knowers.qzh.qzhserver.dao.entity.UserDO;
import team.knowers.qzh.qzhserver.dto.req.PublicAnswerReqDTO;
import team.knowers.qzh.qzhserver.dto.req.PublicQuestionReqDTO;
import team.knowers.qzh.qzhserver.dto.req.QuestionPageReqDTO;
import team.knowers.qzh.qzhserver.dto.resp.AnswerRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.HomeAnswerRespDTO;
import team.knowers.qzh.qzhserver.dto.resp.QuestionPageRespDTO;
import team.knowers.qzh.qzhserver.service.QuestionAnswerService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xtg
 */
@RestController
@RequiredArgsConstructor
public class QuestionAnswerController {
    private final QuestionAnswerService questionAnswerService;

    /**
     * 发布提问
     */
    @PostMapping("/api/qzh-server/admin/v1/QA/Q/public")
    public Result<Boolean> publicQuestion(@RequestBody PublicQuestionReqDTO reqDTO) {
        return Results.success(questionAnswerService.publicQuestion(reqDTO));
    }

    /**
     * 回复某人提问
     */
    @PostMapping("/api/qzh-server/admin/v1/QA/A/public")
    public Result<Boolean> publicAnswer(@RequestBody PublicAnswerReqDTO reqDTO) {
        return Results.success(questionAnswerService.publicAnswer(reqDTO));
    }

    /**
     * 分页展示某段落提问
     */
    @GetMapping("/api/qzh-server/admin/v1/QA/Q/page")
    public Result<IPage<QuestionPageRespDTO>> pageQuestion(QuestionPageReqDTO requestParam) {
        return Results.success(questionAnswerService.pageQuestion(requestParam));
    }

    /**
     * 显示某问题下所有回答
     */
    @GetMapping("/api/qzh-server/admin/v1/QA/A")
    public Result<List<AnswerRespDTO>> allAnswer(@RequestParam("replyer") Long replyer) {
        return Results.success(questionAnswerService.allAnswer(replyer));
    }

    /**
     * 某用户最近评论
     */
    @GetMapping("/api/qzh-server/admin/v1/QA/recent")
    public Result<List<HomeAnswerRespDTO>> homeUserAnswerByTimeDesc(@RequestParam("userId") Long userId) {
        return Results.success(questionAnswerService.homeUserAnswerByTimeDesc(userId));
    }
}
